/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package xmarti.vacaxm.test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.xml.sax.SAXException;
import xmarti.vacaxm.format.FormatJSplitPane;
import xmarti.vacaxm.format.FormatJSplitPaneXML_DOM;

public class testXML {

        public static void main(String[] args)  {
                int lectura_o_escritura = 1; // 0 == escritura, 1 == lectura
                switch(lectura_o_escritura) {
                        case 0:
                                // lista de pedidos
                                
                                ArrayList<Double> cols = new ArrayList<Double>();
                                
                                
                                
                                cols.add(new Double(0.5));
                                cols.add(new Double(0.7));
                                
                                // creamos los procesadores en DOM y en SAX
                                FormatJSplitPaneXML_DOM dom = new FormatJSplitPaneXML_DOM();
                                //PedidosXML_SAX sax = new PedidosXML_SAX();
                                
                                // escritura con DOM
                                File folder = new File("format");
                                if(!folder.isDirectory())folder.mkdir();
                                FormatJSplitPane format= new FormatJSplitPane(cols,10);
                try {
                    dom.FormatJSplitPaneToXML(format, "format/Cows.xml");
                } catch (TransformerException ex) {
                    Logger.getLogger(testXML.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(testXML.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ParserConfigurationException ex) {
                    Logger.getLogger(testXML.class.getName()).log(Level.SEVERE, null, ex);
                }
                                break;
                        case 1:
                                // lectura de fichero, quitar comentario en el caso que se quiera probar
                                FormatJSplitPane formatRead=null;
                                FormatJSplitPaneXML_DOM dom1 = new FormatJSplitPaneXML_DOM();
                try {
                    formatRead = dom1.XMLtoFormatJSplitPane("format/Cows.xml");
                    for(int i=0;i< formatRead.getCols().size();i++)
                                    System.out.println(formatRead.getCols().get(i));
                                    
                                 System.out.println("resize: " + formatRead.getResizeWeight());
                } catch (ParserConfigurationException ex) {
                    Logger.getLogger(testXML.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println(ex.getCause().toString());
                } catch (IOException ex) {
                    System.out.println(ex.getClass());
                } catch (SAXException ex) {
                    Logger.getLogger(testXML.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println(ex.getCause().toString());
                }
                                
                                break;
                        default:
                                System.out.println("lectura_o_escritura == 0 -> Escritura");
                                System.out.println("lectura_o_escritura == 1 -> Lectura");
                                break;
                }
        }
}